<?php
/**
 * @author: xuzhengyang
 * @Time: 2023/2/11   10:50
 */


namespace app\event\deliver;

class KafakaQueue
{

    public static function sendJob($job,$params,$topic)
    {
        $conf = new \Rdkafka\Conf();
        $conf->set("metadata.broker.list","192.168.80.26:9092");
        $producer = new \RdKafka\Producer($conf);
        $topic = $producer->newTopic($topic);
        $accountId = time();
        $message = [
            'job' =>$job,
            'id' => $accountId,
            'params' => $params,
        ];

        $payload = json_encode($message);

        $topic->produce(RD_KAFKA_PARTITION_UA, 0, $payload, $accountId);
        $producer->flush(-1);
        return true;
    }

}